package com.bbx.taxi.client.Util;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.client.Service.DialogService;
import com.bbx.taxi.client.Service.LoginService;
import com.bbx.taxi.client.widget.Dailog.MyPhotoDailog;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.ImageView;

public class HttpBitmap {
	public static Context context;
	public static void getHttpBitmap(Context mContext,String uri) {
		context=mContext;
		new DownloadImageTask().execute(uri);

	}

	public static class DownloadImageTask extends AsyncTask<String, Void, Drawable> {

		protected Drawable doInBackground(String... urls) {
			return loadImageFromNetwork(urls[0]);
		}

		protected void onPostExecute(Drawable result) {
			DialogService.result=result;
			context.startService(new Intent(context, DialogService.class));
		}
	}

	public static Drawable loadImageFromNetwork(String imageUrl) {
		Drawable drawable = null;
		try {
			// 可以在这里通过文件名来判断，是否本地有此图片
			drawable = Drawable.createFromStream(
					new URL(imageUrl).openStream(), "image.jpg");
		} catch (IOException e) {
			Log.d("test", e.getMessage());
		}
		if (drawable == null) {
			Log.d("test", "null drawable");
		} else {
			Log.d("test", "not null drawable");
		}

		return drawable;
	}
}
